<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>广东省传播平台-刊例资源列表</title>
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/common.css" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/css/tag.css" />
		<script type="text/javascript" src="<%=path%>/js/jquery-1.7.2.js"></script>
		<script type="text/javascript">
	function pageSub(currentPage) {
		 var reg=/^\d*?$/;
		 var total =${page.totalPages};
		 if(reg.test(currentPage)){
		 	if(currentPage > total){
		 		$("#currentPage").val(total);
		 	}else{
		 		$("#currentPage").val(currentPage);
		 	}
		 	
			document.forms[0].action="mediumAction.action";
			document.forms[0].submit();
		}else{
			  alert("请输入数字!"); 
		}
	}
	
	function doSubmit(url){
		document.forms[0].action=url;
		document.forms[0].submit();
	}
	
	//重置
	function rewlset(){
		var myDate = new Date(); 
		var year = myDate.getFullYear().toString(10).substring(0,4);//当年
		//alert(year);
		$("#mediumName").val("");//关键字下拉菜单
	}
	
	function doDel(id){
		var mediaID = $("#mediaID").val();
		if(confirm('确定删除该条记录？')){
			$.ajax({
		        url: "delMediumAction.action?"+new Date()+"&id="+id,
		        type:"POST",
		        cache:false,
		        success: function(data)
		        {
			    	if(data.message == "success")
			    	{
		        		alert("该条记录删除成功！");
		        		//alert(mediaID);
		        		window.location.href="mediumAction.action?mediaID="+mediaID+"&contractYear="+$("#contractYear_01").val()+"&mediaType1="+$("#mediaType1_01").val()+"&priceID="+$("#priceID_01").val();
		        		//doSubmit("mediumAction.action?mediaID="+mediaID);
		        	}
		        	if(data.message == "error"){
			    		alert("删除失败,项目刊例正在使用 ！");
		        	}
		   		}
	     	});
		}
	}
	
	function doSelect(url){
		if(find()){
			document.forms[0].action=url;
			document.forms[0].submit();
		}
	}
	
	function find(){
		var mediumName = $('#mediumName').val();
		//去除空格
		$('#mediumName').val(trim(mediumName));
		
		if(trim(mediumName)==''){
		$("#mediumName").val('');}
		if(null !=mediumName){
			if(mediumName.indexOf("%")>-1){
				alert("刊例名称不能包含'%'符号！");
				return false;
			}
			if(mediumName.indexOf("@")>-1){
				alert("刊例名称不能包含'@'符号！");
				return false;
			}
			if(mediumName.indexOf("<")>-1){
				alert("刊例名称不能包含'<'符号！");
				return false;
			}
			if(mediumName.indexOf(">")>-1){
				alert("刊例名称不能包含'>'符号！");
				return false;
			}
			if(mediumName.indexOf("&")>-1){
				alert("刊例名称不能包含'&'符号！");
				return false;
			}
		}
		
		
		return true;
	}
	function trim(str) 
		{
		str = str.replace( /^\s*/, "");
		str = str.replace( /\s*$/, "");
		str = str.replace( /^[" "|"　"]*/, "");
		str = str.replace( /[" "|"　"]*$/, ""); 
		return str;
	} 
</script>
	</head>
	<body>
		<script type="text/javascript">
	$(function(){
        //selectNav('nav2');
    });
</script>
		<!-- 顶栏start -->
		<jsp:include page="../common/top.jsp"></jsp:include>
		<!-- 顶部end -->

		<!-- 顶部start -->
		<div id="main">
			<div class="body">
				<jsp:include page="../common/nav.jsp"></jsp:include>
				<!-- 主体 -->
				<div class="main_body">
					<form action="" method="post">
						<table class="condition bg1"
							style="width: 100%; font-size: 14px; font-weight: bold; color: #000000;"
							align="center">
							<tr>
								<td width="20%" style="height: 40px;">
									&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;刊例名称：
								   <input type="text" id="mediumName" name="mediumName"
											class="text" value="${mediumName}" />
								</td>
								<td width="41%" style="height: 40px;">
									<input type="button" value="搜索" class="btn-title" 
										onclick="doSelect('mediumAction.action');" />
							  &nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="重置" class="btn-title" onclick="rewlset();"/>&nbsp;&nbsp;</td>
							    <td width="17%" style="height: 40px;" align="right"><input name="button" type="button"
										onclick="doSubmit('toAddMediumAction.action');" class="btn-title" value="新增" />&nbsp;&nbsp;</td>
							</tr>
						</table>
						<div id="list_div" style="overflow-x: scroll;">
							<input type="hidden" name="currentPage" id="currentPage" />
							<input type="hidden" id="mediaID" name="mediaID" value="${mediaID}" />
							<input type="hidden" id="contractYear_01" name="contractYear" value="${contractYear}" />
							<input type="hidden" id="mediaType1_01" name="mediaType1" value="${mediaType1}" />
							<input type="hidden" id="priceID_01" name="priceID" value="${priceID}" />
							<div style="width:3500px;">
							<table class="table_list" width="100%">
								<tr class="bg">
									
									<th width="150">
										刊例名称
									</th>
									<th width="150">
										媒体名称
									</th>
									<th width="150">
										媒体类型
									</th>
									<th width="150">
										年度
									</th>
									<th width="150">
										地区
									</th>
									<s:iterator id="sx" value="shuXingList">
										<th width="<s:if test='#sx.datavalue.length()>10'>300</s:if>">
											${sx.datavalue}
										</th>
									</s:iterator>
									<th width="100">
										操作
									</th>
								</tr>
								<s:iterator id="medium" value="mediumList">
										<tr>
									<s:iterator id="m" value="medium" status="status">
										<s:if test="#status.index!=0">
										<td style="word-break:break-all;">
											<c:if test="${empty m}">
												无
											</c:if>
											<s:if test="#status.index==1">
											<a href="#" class="underline" style="cursor:hand;" title="${medium[1]}" onclick="doSubmit('toMediumDetailsAction.action?id=${medium[0]}');">
												<s:if test="#medium[1].length()>15">
													<label title="${medium[1]}">
														<s:property value="#medium[1].substring(0,15)+'...'" />
													</label>
												</s:if>
												<s:else>
													<s:property value="#medium[1]" />
												</s:else>
											</a>
											</s:if>
											<s:else>
												<c:if test="${!empty m}">
													<s:if test="#m.length()>100">
													<label title="${m}">
														<s:property value="#m.substring(0,100)+'...'" />
													</label>
													</s:if>
													<s:else>
														<s:property value="#m" />
													</s:else>
												</c:if>
											</s:else>
										</td>
										</s:if>
										<!-- ${m}_____${medium[i.index+1]} -->
									</s:iterator>
										<td>
											<c:if test="${logUser.cityName eq medium[5]}">
											<a href="#" title="编辑"
												onclick="doSubmit('toUpdateMediumAction.action?id=${medium[0]}');">
												<img src="<%=path%>/images/modify.gif" alt="编辑"
													align="absmiddle" /> </a>
											</c:if>
											<a href="#" title="详情"
												onclick="doSubmit('toMediumDetailsAction.action?id=${medium[0]}');">
												<img src="<%=path%>/images/detail.gif" alt="详情"
													align="absmiddle" /> </a>
											<c:if test="${logUser.cityName eq medium[5]}">
											<a href="#" onclick="doDel(${medium[0]});" title="删除"> <img
													src="<%=path%>/images/delete.gif" alt="删除"
													align="absmiddle" /> </a>
											</c:if>
										</td>
										</tr>
									</s:iterator>
									<tr>
										<td colspan="99">
											&nbsp;<br/>
										</td>
									</tr>
							</table>
							</div>
						</div>
						<!-- 分页 -->
						<jsp:include page="/jsp/common/page.jsp"></jsp:include>
					</form>
				</div>
			</div>
		</div>
		<!-- 顶部end -->


		<!-- 底部start -->
		<div id="bottom">
			<div class="body">
				<label>
					版权所有&nbsp;&nbsp;&nbsp;&nbsp;2012东莞移动
				</label>
			</div>
		</div>
		<!-- 底部end -->
	</body>
</html>